﻿using GadgetStore.Data.Models;
using GadgetStore.Web.Adapters;
using GadgetStore.Web.Adapters.Interfaces;
using GadgetStore.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace GadgetStore.Web.Controllers
{
    [Authorize(Roles="Admin")]
    public class ApiPictureController : ApiController
    {
        private IPicture _adapter;
        public ApiPictureController()
        {
            _adapter = new PictureAdapter();
        }
        [AllowAnonymous]
        public IHttpActionResult GET(int id = -1)
        {
            //Do we need a get all method for picts?
            if (id == -1)
            {
                List<Picture> Pictures = _adapter.GetAllPicts();
                return Ok(Pictures);
            }
            else
            {
                Picture Picture = _adapter.GetOnePict(id);
                return Ok(Picture);
            }
        }
        [HttpPost]
        public IHttpActionResult POST(GadgetVM vm)
        {
            int gadgetId = _adapter.NewPict(vm);
            return Ok(gadgetId);
        }
        [HttpDelete]
        public IHttpActionResult DELETE(int id)
        {
            int gadgetId =_adapter.DeletePict(id);
            return Ok(gadgetId);
        }
        [HttpPut]
        public IHttpActionResult PUT(Picture picture)
        {
            int gadgetId = _adapter.UpdatePict(picture);
            return Ok(gadgetId);
        }
    }
}
